﻿(function ($) {
    $.probleminfojs = {

        uploadvideo: function () {
            var formData = new FormData();
            formData.append('Action', "uploadvideo");
            //var file = document.getElementById("file").files[0];
            formData.append('file', $('#file')[0].files[0]);
            console.log(formData);
            $.ajax({
                url: "./ProblemInfo.ashx",
                type: 'POST',
                data: formData,
                contentType: false,
                processData: false,
                mimeType: "multipart/form-data",
                success: function (data) {
                    console.log($.parseJSON(data));
                    var jsondata = $.parseJSON(data);
                    if (jsondata.code == 1) {
                        $("#VideoPath").val(jsondata.msg);
                        dialogMsg("文件上传成功", 1);
                    }
                    else {
                        dialogMsg(jsondata.msg, -1);
                    }
                },
                error: function (data) {
                    dialogMsg("上传失败", -1);
                }
            });
        },

        //  根据 客户ID 获取设备卡号select下拉列表
        getEquNoListByCustomerID: function (CustomerID) {

            $("#CustomerEqu").empty();
            var _html = "";
            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "getEquNoListByCustomerID",
                    CustomerID: CustomerID
                },
                async: false,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    //console.log(data);
                    if (data.length > 0) {
                        for (key in data) {
                            _html += "<option value=\"" + data[key].EquNo + "\" >" + data[key].EquNo
.trim() + "</option>";
                        }
                        $("#CustomerEqu").html(_html);
                    }
                    else {
                        $("#CustomerEqu").html("<option value=''>请选择</option>");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        //  根据客户名   获取联系人 select 
        getToUserNoByCustomerID: function (CustomerID) {

            $("#ToUserNo").empty();
            var _html = "";
            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "getToUserNoByCustomerID",
                    CustomerID: CustomerID
                },
                async: false,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    _html += "<option value=''>请选择</option>";
                    if (data.length > 0) {
                        for (key in data) {
                            console.log(data[key])
                            _html += "<option value=\"" + data[key].UserNo + "\" >" + data[key].UserName
.trim() + "</option>";
                        }
                        $("#ToUserNo").html(_html);
                    }
                    else {
                        $("#ToUserNo").html("<option value=''>请选择</option>");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        // 当宏大人员登录  获取客户select 
        getCustomerListByHongDa: function () {
            $("#CustomerID").empty();
            var _html = "";
            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "getCustomerListByHongDa"
                },
                async: false,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    //console.log(data);
                    _html += "<option value=''>请选择</option>";
                    if (data.length > 0) {
                        for (key in data) {
                            _html += "<option value=\"" + data[key].CustomerID + "\" >" + data[key].CustomerName
.trim() + "</option>";
                        }
                        $("#CustomerID").html(_html);
                    }
                    else {
                        $("#CustomerID").html("<option value=''>请选择</option>");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        //保存新增问题信息
        saveProblemInfo: function (CustomerName,FromUserNo, ToUserNo, ProblemIssue, ProblemImage, VideoPath, grid) {

            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "saveProblemInfo",
                    CustomerName: CustomerName,
                    FromUserNo: FromUserNo,
                    ToUserNo: ToUserNo,
                    ProblemIssue: ProblemIssue,
                    ProblemImage: ProblemImage,
                    VideoPath: VideoPath
                },
                type: "post",
                async: true,
                datatype: "json",
                success: function (data) {
                    if (data == "success") {
                        Loading(false);
                        dialogMsg("保存成功", 1);
                        grid.trigger("reloadGrid");
                        dialogClose();
                    }
                    else if (data == "falut") {
                        dialogMsg("保存失败", -1);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                },
                beforeSend: function () {
                    Loading(true, "正在保存数据");
                },
                complete: function () {
                    Loading(false);
                }
            });
        },

        // 留言回复
        saveMessageRepate: function (MessageID,MessageWordsRepate, FromUserNo, ToUserNo, ProblemImage, VideoPath, grid) {

            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "saveMessageRepate",
                    MessageID: MessageID,
                    MessageWordsRepate: MessageWordsRepate,
                    FromUserNo: FromUserNo,
                    ToUserNo: ToUserNo,
                    ProblemImage: ProblemImage,
                    VideoPath: VideoPath
                },
                type: "post",
                async: true,
                datatype: "json",
                success: function (data) {
                    if (data == "success") {
                        Loading(false);
                        dialogMsg("保存成功", 1);
                        grid.trigger("reloadGrid");
                        dialogClose();
                    }
                    else if (data == "falut") {
                        dialogMsg("保存失败", -1);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                },
                beforeSend: function () {
                    Loading(true, "正在保存数据");
                },
                complete: function () {
                    Loading(false);
                }
            });
        },

        //根据ID获取视频url
        getVideoByProblemID: function (ProblemID) {
            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "getVideoByProblemID",
                    ProblemID: ProblemID
                },
                async: false,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    //data = JSON.parse(data);
                    console.log(data);
                    $("#videoname").attr('src', '../ProblemInfo/uploadFilePath/' + data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        //根据ID获取图片url  构造轮播图
        getImgByProblemID: function (ProblemID) {
            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "getImgByProblemID",
                    ProblemID: ProblemID
                },
                async: false,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    //data = JSON.parse(data);
                    
                    var str = data.split(',');
                    //$("#videoname").attr('src', '../ProblemInfo/uploadFilePath/' + data);
                    var optionstr = "";
                    for (let i = 0; i < str.length; i++) {
                        var srcstr = "uploadFilePath" + '\\' + str[i];
                        optionstr += "<li>";
                        optionstr += "<img src=\"" + srcstr + "\"  width='600px;' height='400px;'>";
                        optionstr += "</li>";
                    }
                    console.log(optionstr);
                    $("#slider").append(optionstr);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        // 根据留言ID 获取留言人 留言内容
        getMessageInfoByID: function (MessageID) {
            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "getMessageInfoByID",
                    MessageID: MessageID
                },
                async: false,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    //data = JSON.parse(data);
                    console.log(data);
                    $("#MessageWords").val(data);
                    //$("#videoname").attr('src', '../ProblemInfo/uploadFilePath/' + data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        deleteCustomerEquInfo: function (CustomerEquID, grid) {
            $.ajax({
                url: "./CustomerHandler.ashx",
                data: {
                    Action: "deleteCustomerEquInfo",
                    CustomerEquID: CustomerEquID
                },
                type: "post",
                async: true,
                datatype: "json",
                success: function (data) {
                    console.log(data);
                    if (data == "success") {
                        Loading(false);
                        dialogMsg("删除成功", 1);
                        grid.trigger("reloadGrid");
                        dialogClose();
                    }
                    else if (data == "falut") {
                        dialogMsg("删除失败", -1);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                },
                beforeSend: function () {
                    Loading(true, "正在保存数据");
                },
                complete: function () {
                    Loading(false);
                }
            });
        },

        // 删除问题
        deleteProblemInfo: function (ProblemID) {
            $.ajax({
                url: "./ProblemInfo.ashx",
                data: {
                    Action: "deleteProblemInfo",
                    ProblemID: ProblemID
                },
                type: "post",
                async: true,
                datatype: "json",
                success: function (data) {
                    console.log(data);
                    if (data == "success") {
                        Loading(false);
                        dialogMsg("删除成功", 1);
                        grid.trigger("reloadGrid");
                        dialogClose();
                    }
                    else if (data == "falut") {
                        dialogMsg("删除失败", -1);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                },
                beforeSend: function () {
                    Loading(true, "正在保存数据");
                },
                complete: function () {
                    Loading(false);
                }
            });
        }
    };


    $(function () {

    });
})(jQuery);